Skip to content

feat: validate generated models against source JSON Schema - #68

Merged
lightsofapollo merged 61 commits into
mainfrom
fix/boolean-subschemas
Aug 28, 2026
Merged

feat: validate generated models against source JSON Schema#68
lightsofapollo merged 61 commits into
mainfrom
fix/boolean-subschemas

Conversation

@lightsofapollo

@lightsofapollo lightsofapollo commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add deterministic JSON Schema sample generation for representable component schemas, hydrate those samples through the exact generated Rust models, serialize them back to JSON, validate the output against the source schema, and require a stable second round trip.
  • Integrate that validation into focused and full scripts/spec-compile.sh runs with aggregate failure reporting, retained artifacts, coverage totals, and explicit skip classifications.
  • Fix every generator, analyzer, fixture, and harness defect exposed by the complete 55-spec corpus, including union dispatch, discriminator semantics, allOf projection, nullable fields and references, dynamic object members, wide integers, binary/time wire formats, inline-schema identity, and boolean subschemas.

The authoritative uninterrupted corpus run completed with:

  • 55 passed
  • 0 generation failures
  • 0 cargo-check failures
  • 0 round-trip planning failures
  • 0 round-trip failures
  • 28,139 / 29,045 component schemas exercised
  • 103,031 schema-valid synthetic samples
  • 906 explicit schema skips: 52 source-invalid, 76 dependent, 778 synthesis-limited

Generated compatibility

  • Generated model or method signatures: breaking corrections are possible. Discriminated-union payloads retain required tag fields; optional nullable fields preserve missing versus explicit null with Option<Option<T>>; integer widths follow the effective schema domain; and inline types use collision-safe provenance-aware names.
  • Query/path/header/body wire behavior: anyOf preserves complete object input, oneOf rejects ambiguous/no-match values, discriminator mappings and literal domains are enforced, required nullable values serialize as explicit null, binary model values remain JSON strings, and RFC 3339 offsets round-trip exactly.
  • Generated runtime dependencies or features: adds the internal-tools-only schema-roundtrip binary. Corpus scratch crates add jsonschema as a dev dependency only when round-trip validation is enabled.
  • Configuration defaults or migrations: schema round trips are enabled by default for non-parse-only spec compile runs. Set SPEC_COMPILE_SCHEMA_ROUNDTRIP=0 only to isolate unrelated compile failures.
  • Remaining unsupported OpenAPI shapes: Microsoft Graph remains generate-only because compile verification reaches approximately 14.3 GB RSS; Gitea remains excluded because it is Swagger 2.0. Per-schema omissions are reported explicitly in the coverage totals above.

Validation

  • Added or updated focused fixtures and behavioral regression tests.
  • Reviewed changed snapshots; changes correspond to corrected generated behavior.
  • cargo fmt --all -- --check
  • cargo clippy --all-features -- -D warnings
  • cargo test --all-features
  • scripts/install-smoke.sh (GitHub CI)
  • Full 55-spec scripts/spec-compile.sh generator/compile/schema-round-trip corpus (GitHub CI)
  • Official openai 2.45.0 and anthropic 0.120.0 SDK compatibility tests against generated Axum servers.
  • Generated Rust SSE client against a private LM Studio instance: OpenAI emitted 16 typed chunks; Anthropic emitted the complete typed event lifecycle from message_start through message_stop.
  • Official OpenAI and Anthropic Python SDK unary and streaming smoke tests against the same private LM Studio instance.
  • Updated README, CONTRIBUTING, and CHANGELOG documentation.

Notes for reviewers

This PR contains 61 commits across 121 files because each independently reproducible corpus failure was tracked and fixed with focused coverage. All 68 child issues under Beads issue openapi-generator-cu5 are closed.

Suggested review path:

  1. src/schema_roundtrip.rs, src/bin/schema-roundtrip.rs, and scripts/spec-compile.sh for the validation architecture.
  2. src/analysis.rs, src/generator.rs, and src/openapi.rs for generated-model correctness fixes.
  3. New focused tests, then fixture corrections guarded by tests/corpus_fixture_schema_validity.rs.

lightsofapollo and others added 30 commits August 27, 2026 09:57
JSON Schema 2020-12 allows `true` and `false` in any schema position: `true`
accepts every value, `false` accepts none. `properties: {extra: true}` is how a
spec says "this key exists, any value". The parser modeled schemas as objects
only, so one boolean anywhere took the whole document down with the same opaque
error #60 was about.

`Schema::Bool` models it once, at the type every position already uses, rather
than adding another per-keyword enum. That makes `Items::Bool` redundant —
`items: false` is now the ordinary single-schema slot holding a boolean schema —
so it is gone, and closedness reads the boolean through it.

Generated code cannot say more than `serde_json::Value` for either spelling, so
what changes is that the document parses and its other fields keep their types.
`true` reports as `any-schema` and `false` as `never-matches`, both faithful. In
a union a `true` branch makes the whole union unconstrained, and a `false`
branch can never be taken and is dropped: `oneOf: [A, false]` is `A`.

Also reads integer keywords written as decimals (`maxItems: 2.0`), which JSON
Schema permits and the suite exercises; `2.5` is still an error rather than a
silent round.

The vendored JSON Schema 2020-12 corpus goes from 38 parse failures to zero,
with no round-trip loss — the boolean fix accounts for 30 of them across
`contains`, `if-then-else`, `items`, `not`, `patternProperties`, `prefixItems`,
`properties`, `propertyNames`, and `dependentSchemas`.

Closes #63

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TD3TSeWKu4VqLtEnRMDjry
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openapi-to-rust Ready Ready Preview Aug 28, 2026 4:38pm

Request Review

@lightsofapollo
lightsofapollo merged commit ba32d21 into main Aug 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant